package com.xb.loan.usercenter.account.common;

import com.xb.loan.account.service.bean.CashInfoVO;
import com.xb.loan.account.service.bean.CashStatVO;
import com.xb.loan.account.service.bean.CouponInfoVO;
import com.xb.loan.account.service.bean.LotCashInfoVO;
import com.xb.loan.account.service.constant.AccountConst;
import com.xb.loan.account.service.exception.IAccountServiceException;
import com.xb.loan.log.exception.BizException;
import com.xb.loan.log.exception.IBizException;
import com.xb.loan.usercenter.account.dao.bean.CashInfo;
import com.xb.loan.usercenter.account.dao.bean.CouponInfo;
import com.xb.loan.usercenter.account.dao.bean.LotCashInfo;
import com.xb.loan.usercenter.service.user.bean.UserInfoVO;
import com.xb.loan.util.log.DefaultLoggerFacotry;
import org.slf4j.Logger;

public class VerifySet {
	private static Logger logger = DefaultLoggerFacotry.getLogger(VerifySet.class);
	public static String getSourcePosition() {
		Exception e = new RuntimeException();
		StackTraceElement element = e.getStackTrace()[2];
		StringBuffer buffer = new StringBuffer();
		buffer.append("class=").append(element.getClassName()).append("\t")
			.append("method=").append(element.getMethodName()).append("\t");
		return buffer.toString();
	}
	
	/**
	 * 验证用户ID是否为null
	 * @param userId 用户ID
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyUserId(String userId) throws BizException {
		if(userId == null || userId.length() == 0){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("userId=").append(userId)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
	}
	
	/**
	 * 验证用户信息是否为null
	 * @param userInfoVO 用户信息
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyUserInfoVO(UserInfoVO userInfoVO) throws BizException{
		if(userInfoVO == null){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("userInfoVO=").append(userInfoVO)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
	}

	/**
	 * 验证金额不能为负值
	 * @param money
	 * @throws BizException
	 *                 2015年9月1日 by wenju.song
	 */
	public static void verifyMoney(double money, String foreignId) throws BizException {
		if (money <= 0) {
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("money=").append(money).append("\tforeignId=").append(foreignId)
			.append("\t").append(IAccountServiceException.moneyNotPositive.getMessage());
			logger.warn(buffer.toString());
			throw IAccountServiceException.moneyNotPositive;
		}
	}
	
	/**
	 * 验证账户ID是否为null
	 * @param accountId 账户ID
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyAccountId(String accountId) throws BizException{
		if(accountId == null || accountId.length() == 0){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("accountId=").append(accountId)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
	}
	
	/**
	 * 验证现金账户是否为null
	 * @param cashInfoVO 现金账户信息
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyCashInfoVO(CashInfoVO cashInfoVO) throws BizException{
		if(cashInfoVO == null){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("cashInfo=").append(cashInfoVO)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
	}
	
	/**
	 * 验证现金账户是否处于正常状态
	 * @param cashInfoVO 现金账户信息
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyCashInfoVOIsNormal(CashInfoVO cashInfoVO) throws BizException{
		if(cashInfoVO == null){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("cashInfoVO=").append(cashInfoVO)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
		if(cashInfoVO.getStatus() != AccountConst.AccountStatus_Normal){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("accountId=").append(cashInfoVO.getAccountId())
			.append("\t").append(IAccountServiceException.accountNotNormal.getMessage());
			logger.warn(buffer.toString());
			throw IAccountServiceException.accountNotNormal;
		}
	}
	
	/**
	 * 验证现金账户是否处于正常状态
	 * @param cashInfo 现金账户信息
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyCashInfoIsNormal(CashInfo cashInfo) throws BizException{
		if(cashInfo == null){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("cashInfoVO=").append(cashInfo)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
		if(cashInfo.getStatus() != AccountConst.AccountStatus_Normal){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("accountId=").append(cashInfo.getAccountId())
			.append("\t").append(IAccountServiceException.accountNotNormal.getMessage());
			logger.warn(buffer.toString());
			throw IAccountServiceException.accountNotNormal;
		}
	}
	
	/**
	 * 验证彩金账户是否为null
	 * @param lotCashInfoVO 彩金账户信息
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyLotCashInfoVO(LotCashInfoVO lotCashInfoVO) throws BizException{
		if(lotCashInfoVO == null){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("lotCashInfoVO=").append(lotCashInfoVO)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
	}
	
	/**
	 * 验证彩金账户是否处于正常状态
	 * @param lotCashInfo 彩金账户信息
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyLotCashInfoIsNormal(LotCashInfo lotCashInfo) throws BizException{
		if(lotCashInfo == null){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("lotCashInfo=").append(lotCashInfo)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
		if(lotCashInfo.getStatus() != AccountConst.AccountStatus_Normal){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("accountId=").append(lotCashInfo.getAccountId())
			.append("\t").append(IAccountServiceException.accountNotNormal.getMessage());
			logger.warn(buffer.toString());
			throw IAccountServiceException.accountNotNormal;
		}
	}
	
	/**
	 * 验证couponId是否为null
	 * @param couponId 礼券账户ID
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyCouponId(String couponId) throws BizException{
		if(couponId == null || couponId.length() == 0){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("couponId=").append(couponId)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
	}
	
	/**
	 * 验证礼券账户是否为null
	 * @param couponInfoVO 礼券账户信息
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyCouponInfoVO(CouponInfoVO couponInfoVO) throws BizException{
		if(couponInfoVO == null){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("couponInfoVO=").append(couponInfoVO)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
	}
	
	/**
	 * 验证礼券账户是否处于正常状态
	 * @param couponInfo 礼券账户信息
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyCouponInfoIsNormal(CouponInfo couponInfo) throws BizException{
		if(couponInfo == null){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("couponInfo=").append(couponInfo)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
		if(couponInfo.getStatus() != AccountConst.AccountStatus_Normal){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("accountId=").append(couponInfo.getAccountId())
			.append("\t").append(IAccountServiceException.accountNotNormal.getMessage());
			logger.warn(buffer.toString());
			throw IAccountServiceException.accountNotNormal;
		}
	}

	/**
	 * 验证cashStatVO是否为null
	 * @param cashStatVO 
	 * @throws BizException
	 * 2015年9月13日 by wenju.song
	 */
	public static void verifyCashStatVO(CashStatVO cashStatVO) throws BizException{
		if(cashStatVO == null){
			StringBuffer buffer = new StringBuffer();
			buffer.append(getSourcePosition()).append("cashStatVO=").append(cashStatVO)
			.append("\t").append(IBizException.inputParameterIsWrong.getMessage());
			logger.warn(buffer.toString());
			throw IBizException.inputParameterIsWrong;
		}
	}
}
